package Text;

import java.util.Arrays;

public class visitedvertex {
    int[] already;
    int[] dis;
    public  static final int N=65535;
    public visitedvertex(int index,int length){
        already=new int[length];
        dis=new int[length];
        Arrays.fill(dis,N);
        dis[index]=0;
        already[index]=1;
    }

    public int getDis(int index) {
        return dis[index];
    }

    public void setDis(int index,int len) {
        dis[index]=len;
    }

    public boolean in(int index){
        return already[index]==1;
    }

    public void show(){
//        System.out.println(Arrays.toString(already));
        System.out.println(Arrays.toString(dis));
    }

    public void update(Graph graph,int index){
        int len=0;
        for (int i = 0; i < graph.vertex.length; i++) {
            len=graph.matrix[index][i]+dis[index];
            if(!in(i)&&len<getDis(i)){
                setDis(i,len);
            }
        }
    }

    public int updateArr(){
        int min=N,index=0;
        for (int i = 0; i < already.length; i++) {
            if(!in(i)&&dis[i]<min){
                min=dis[i];
                index=i;
            }
        }
        already[index]=1;
        return index;
    }
}
